//
//  RZQDataCollectionViewCell.m
//  LastOne
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "RZQDataCollectionViewCell.h"
#import "FitHeader.h"
#import <UIImageView+WebCache.h>
#import "NightHeader.h"
@implementation RZQDataCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatAction];
    }
    return self;
}
-(void)creatAction
{
    _titleLabel = [[UILabel alloc]init];
      _titleLabel.frame =CGRectMake(0, self.contentView.frame.size.width / 2 + 10 * FitHeight, self.contentView.frame.size.width, self.contentView.frame.size.height / 2  - 60 * FitHeight);
    [self.contentView addSubview:_titleLabel];
    
    _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 2)];
    
    [self.contentView addSubview:_imageView];
    
    _cirImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5 * FitWidth, 150 * FitHeight, 20 * FitWidth, 20 * FitHeight)];
    [self.contentView addSubview:_cirImageView];
  
    
    _cirLabel = [[UILabel alloc]initWithFrame:CGRectMake(_cirImageView.frame.origin.x + _cirImageView.frame.size.width + 5 * FitWidth, _cirImageView.frame.origin.y, 150 * FitWidth, 18 * FitHeight)];
    [self.contentView addSubview:_cirLabel];
    
    _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5 * FitWidth, 170 * FitHeight,150 * FitWidth, 18 * FitHeight)];
    [self.contentView addSubview:_timeLabel];
 
    _likeImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width - 39 * FitWidth, _cirLabel.frame.origin.y  , 18 * FitWidth, 18 * FitHeight)];
    _likeImage.image  = [UIImage imageNamed:@"xihuan"];
    
    [self.contentView addSubview:_likeImage];
    
    _likeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width - 20 * FitWidth, _cirLabel.frame.origin.y, 30 * FitWidth, 18 * FitHeight)];
    
    [self.contentView addSubview:_likeLabel];
    
    
    
    
    
    _talkImage =  [[UIImageView alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width - 40 * FitWidth, _timeLabel.frame.origin.y  , 18 * FitWidth, 18 * FitHeight)];
    _talkImage.image = [UIImage imageNamed:@"pinglun"];
    [self.contentView addSubview:_talkImage];
    
    _talkLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.contentView.frame.size.width - 20 * FitWidth, _timeLabel.frame.origin.y , 30 * FitWidth, 18 * FitHeight)];
    
    [self.contentView addSubview:_talkLabel];
    
    
    
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    _cirView.backgroundColor = [UIColor whiteColor];
   
   
  
}
-(void)setCirData:(CirleModel *)cirData
{
    if (_cirData != cirData) {
        _cirData = cirData;
        
    }
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_cirData.image] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    [_cirImageView sd_setImageWithURL:[NSURL URLWithString:[_cirData.category objectForKey:@"image_small"]] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    
    _titleLabel.text = _cirData.title ;
    _titleLabel.numberOfLines = 0;
    _titleLabel.font = [UIFont systemFontOfSize:15 * FitWidth];
    [_titleLabel NightWithType:UIViewColorTypeNormal];
    _cirLabel.text = [_cirData.category objectForKey:@"title"];
    _cirLabel.font = [UIFont systemFontOfSize:14 * FitWidth];
    _cirLabel.textColor = [UIColor grayColor];
    
    
    NSDate *date1 = [NSDate date];
    
    
    NSDate *detaildate = [[NSDate alloc]initWithTimeIntervalSince1970:_cirData.publish_time];
    NSTimeInterval interval = [date1 timeIntervalSinceDate:detaildate];
   
    if (interval < 60) {
        _timeLabel.text = @"刚刚";
    }
    else if (interval >= 60 && interval <= 3600)
    {
        _timeLabel.text = [NSString stringWithFormat:@"%ldf分钟前", (long)interval / 60];
    }
    else if (interval >= 3600 && interval <= 3600 * 24 )
    {
        
        _timeLabel.text = [NSString stringWithFormat:@"%ld小时前",(long)interval / 3600];
        
    }
    else if (interval >= 3600 * 24 && interval <= 7200 * 24 )
    {
        NSDateFormatter *dateFormayyer = [[NSDateFormatter alloc]init];
        [dateFormayyer setDateFormat:@" HH:mm"];
        _timeLabel.text =[NSString stringWithFormat:@"昨天 %@", [dateFormayyer stringFromDate:detaildate]];
        
    }
    else
    {
        NSDateFormatter *dateFormayyer = [[NSDateFormatter alloc]init];
        [dateFormayyer setDateFormat:@"MM-dd HH:mm"];
        _timeLabel.text = [dateFormayyer stringFromDate:detaildate];
        
    }
   
    _timeLabel.textColor = [UIColor grayColor];
    [_timeLabel NightWithType:UIViewColorTypeNormal];
    _timeLabel.font = [UIFont systemFontOfSize:12 * FitWidth];
    _likeLabel.text = [NSString stringWithFormat:@"%ld", (long)_cirData.praise_count];
    _likeLabel.font = [UIFont systemFontOfSize:12 * FitWidth];
    [_likeLabel NightWithType:UIViewColorTypeNormal];
    _talkLabel.text = [NSString stringWithFormat:@"%ld", (long)_cirData.comment_count];
    _talkLabel.font = [UIFont systemFontOfSize:12 * FitWidth];
    [_talkLabel NightWithType:UIViewColorTypeNormal];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
